﻿using Microsoft.Practices.Unity;
using UnityDemo.LoggingUtility;
using UnityDemo.Models;

namespace UnityDemo.RegAndResCode
{
    /// <summary>
    /// This sample shows how to Register an interface with multiple classes
    /// in this case the last  regiestered type is the one resolved
    /// </summary>
    internal class RegisterMultipleInterfacesAndClass : ISample
    {
        public RegisterMultipleInterfacesAndClass()
        {
            var container = new UnityContainer(); // UnityInstanceProvider.NewUnityInstance;

            //Registering IDuck and its implementing class
            container.RegisterType<IDuck, KingDuck>();
            container.RegisterType<IDuck, QueenDuck>();

            //Resolving instance of IDuck
            var duck = container.Resolve<IDuck>();

            if (duck is KingDuck)
                LogerInstance.Logger.Write(duck.Name);

            if (duck is QueenDuck)
                LogerInstance.Logger.Write(duck.Name);
        }
    }
}